# Copyright (C) 2009,2010,2011,2012  Marco Restelli
#
# This file is part of:
#   FEMilaro -- Finite Element Method toolkit
#
# FEMilaro is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# FEMilaro is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with FEMilaro; If not, see <http://www.gnu.org/licenses/>.
#
# authors: 
#         Marco Restelli                   <marco.restelli@gmail.com>
#         Carlo de Falco

# List of the object files of the present folder
OBJ= mod_base.o \
     mod_tps_base.o \
     mod_bcs.o \
     mod_cgdofs.o \
     mod_fe_spaces.o \
     mod_grid.o \
     mod_tps_phs_grid.o \
     mod_master_el.o \
     mod_sections.o
# These are the modules that are meant to be USEd by the library users
LIBRARY_MOD_FILES= $(OBJ:.o=.mod)

# General settings -----------------------------------

PWD:=$(shell pwd)
BUILDDIR:=$(BUILDDIR)/fem

# VPATH includes:
#   PWD for the source files (included by default)
#   BUILDDIR for the .o prerequisites
#   LIBDIR for the libfml_general_utilities.a library
VPATH:=$(BUILDDIR) $(LIBDIR)

# clear unfinished targets
.DELETE_ON_ERROR:
# define the phony targets
.PHONY: clean

# Main targets ---------------------------------------

libfem.a: $(OBJ)
	cd $(BUILDDIR) && $(AR) -r $(LIBDIR)/libfem.a $(OBJ)
	for mod in $(LIBRARY_MOD_FILES);     \
        do                                   \
          cp $(BUILDDIR)/$${mod} $(LIBDIR)/; \
        done

# General rule: all the .o depend on the libfml_general_utilities library
%.o: %.f90 libfml_general_utilities.a
	cd $(BUILDDIR) && \
	  $(FC) $(FFLAGS) $(MODFLAG)$(LIBDIR) -c $(PWD)/$<

clean:
	$(RM) $(BUILDDIR)/*.o $(BUILDDIR)/*.ilo $(BUILDDIR)/*.mod \
          $(LIBDIR)/libfem.a
	for mod in $(LIBRARY_MOD_FILES); \
        do                               \
          $(RM) $(LIBDIR)/$${mod};       \
        done

# Specific dependencies: because of USE directives ---
# Notice: here we list only the prerequisites which are not already
# included in the libfml_general_utilities.a library, which is a
# prerequisite of all the .o files listed in this Makefile

mod_base.o: \
  mod_master_el.o

mod_bcs.o: \
  mod_grid.o

mod_cgdofs.o: \
  mod_master_el.o \
  mod_grid.o \
  mod_bcs.o

mod_fe_spaces.o: \
  mod_master_el.o \
  mod_base.o

mod_grid.o: \
  mod_master_el.o

mod_sections.o: \
  mod_grid.o

